using System;
using System.Collections.Generic;

namespace BlazorSodDbManager.Models
{
    public enum DatabaseType
    {
        SqlServer,
        MySQL,
        Oracle,
        SQLite,
        Access,
        PostgreSQL
    }

    public class DatabaseConnection
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public string Server { get; set; } = string.Empty;
        public string Database { get; set; } = string.Empty;
        public string Username { get; set; } = string.Empty;
        public string Password { get; set; } = string.Empty;
        public DatabaseType Type { get; set; }
        public string? ConnectionString { get; set; }
        public int Port { get; set; }

        public string GetConnectionString()
        {
            if (!string.IsNullOrEmpty(ConnectionString))
            {
                return ConnectionString;
            }

            switch (Type)
            {
                case DatabaseType.SqlServer:
                    return $"Data Source={Server};Initial Catalog={Database};User ID={Username};Password={Password};";
                case DatabaseType.MySQL:
                    return $"Server={Server};Port={Port};Database={Database};Uid={Username};Pwd={Password};";
                case DatabaseType.Oracle:
                    return $"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={Server})(PORT={Port}))(CONNECT_DATA=(SERVICE_NAME={Database})));User Id={Username};Password={Password};";
                case DatabaseType.SQLite:
                    return $"Data Source={Database};Version=3;";
                case DatabaseType.Access:
                    return $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={Database};";
                case DatabaseType.PostgreSQL:
                    return $"Host={Server};Port={Port};Database={Database};Username={Username};Password={Password};";
                default:
                    throw new NotSupportedException($"Database type {Type} is not supported.");
            }
        }
    }
} 